/**
 * File:   DeleteAction.java
 * Author: Gvennet
 */
package gui.actions;

import dht.node.DHTNodeModel;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;

/**
 * todo write javadoc
 */
public final class DeleteNodeAction extends AbstractAction
{

	private final DHTNodeModel nodeModel;

	private final JTable nodeTable;

	public DeleteNodeAction(DHTNodeModel nodeModel, JTable nodeTable)
	{
		super("-");
		putValue(SHORT_DESCRIPTION, "Удалить узел");
		putValue(MNEMONIC_KEY, KeyEvent.VK_D);
		this.nodeModel = nodeModel;
		this.nodeTable = nodeTable;
	}

	@Override
	public void actionPerformed(ActionEvent e)
	{

		int index = nodeTable.getSelectedRow();
		if (index >= 0)
		{
			nodeModel.remove(index);
		}
	}
}
